package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.MakeMoney;
import com.juyu.miliao.api.domain.MakeMoneyVO;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MakeMoneyDao {
    @Resource
    private SqlSession sqlSession;

    /**
     * 获取发送邀请用户id 共赚取金币数量
     * @param userId
     * @return
     */
    public int getMakeMoneyDepositSum(long userId){
        return sqlSession.selectOne("getMakeMoneyDepositSum", userId);
    }

    /**
     * 获取发送邀请用户 已邀请到的好友列表
     * @param userId
     * @return
     */
    public List<MakeMoneyVO> getMakeMoneyInfoList(Long userId) {
        return sqlSession.selectList("getMakeMoneyInfoList",userId);
    }

    /**
     * 检测用户是否是首冲用户
     * @param passiveUserId
     * @param makeMoneyType 赚钱类型：1注册10金币 2首冲30金币
     * @return
     */
    public MakeMoney getMakeMoneyByPassiveUserIdAndType(long passiveUserId, int makeMoneyType) {
        Map<String,Object> map = new HashMap<>();
        map.put("passiveUserId",passiveUserId);
        map.put("makeMoneyType",makeMoneyType);
        return sqlSession.selectOne("getMakeMoneyByPassiveUserIdAndType",map);
    }

    public int insertMakeMoney(long activeUserId, long passiveUserId, int makeMoneyType, int deposit,
                               String verifyOpenId, String deviceNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("activeUserId", activeUserId);
        params.put("passiveUserId", passiveUserId);
        params.put("makeMoneyType",makeMoneyType);
        params.put("deposit",deposit);
        params.put("verifyOpenId",verifyOpenId);
        params.put("deviceNo",deviceNo);
        return sqlSession.insert("insertMakeMoney",params);
    }
}
